dotNet / Setup / Json Response - Part2
Json Response
-
Package
Step 1: install microsoft.NewtonsoftJson
Go to tools -> NutGet Package Manager -> Manage NutGet Manager Solution
-
Coding
Step 1: Add AddNewtonsoftJson() in Startup.cs
public void ConfigureServices(IServiceCollection services) { services.AddControllers() .AddNewtonsoftJson(ops => { ops.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; }); } Step2: return json data
using Newtonsoft.Json; .... .... Department d = new Department(); d.DepartmentId = 1; d.DepartmentName = "m"; return JsonConvert.SerializeObject(d);